<?php 	
	header('Access-Control-Allow-Origin: *');
	header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
	header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE');
	
	include('connect.php');
	include('third/PHPExcel/IOFactory.php');

	$file_name = $_FILES['productFile']['name'];
	$file_temp_name = $_FILES['productFile']["tmp_name"];

	if(file_exists('../upload_file/'.$file_name)){
		// echo $file_name.'已存在!';
		unlink('../upload_file/'.$file_name);
	}
	
	move_uploaded_file($file_temp_name,'../upload_file/'.$file_name);
	
	$inputFileName = '../upload_file/'.$file_name;
	// date_default_timezone_set(‘PRC’);
	// 读取excel文件
	try {
		$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
		$objReader = PHPExcel_IOFactory::createReader($inputFileType);
		$objPHPExcel = $objReader->load($inputFileName);
	} catch(Exception $e) {
		var_dump($e);
	}

	// 确定要读取的sheet，什么是sheet，看excel的右下角，真的不懂去百度吧
	$sheet = $objPHPExcel->getSheet(0);
	$highestRow = $sheet->getHighestRow();
	$highestColumn = $sheet->getHighestDataColumn();
	
	$rownum = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
				'AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP'];
	// 获取一行的数据
	for ($row = 2; $row <= $highestRow; $row++){
		$a = $objPHPExcel->getActiveSheet()->getCell("A".$row)->getValue();

		$sql1 = "";
		for($x=0;$x<sizeof($rownum);$x++){
			if($x == sizeof($rownum)-1){
				$sql1 .= "'".$objPHPExcel->getActiveSheet()->getCell($rownum[$x].$row)->getValue()."'";
			}else{
				$sql1 .= "'".$objPHPExcel->getActiveSheet()->getCell($rownum[$x].$row)->getValue()."',";
			}
		}
		
		$sql = 'INSERT INTO productslist VALUES(null,'.$sql1.')';
			
		$db->query($sql);
	}


